package cn.itcast.hiss.server.order;

import cn.hutool.core.util.StrUtil;
import cn.itcast.hiss.server.mapper.GoodsMapper;
import cn.itcast.hiss.server.util.SpringContextHolder;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.springframework.context.ApplicationContext;

/*
 * @author miukoo
 * @description 库存更新
 * @date 2023/8/23 19:12
 * @version 1.0
 **/
public class UpdateStockServiceTask implements JavaDelegate {

    @Override
    public void execute(DelegateExecution execution) {
        ApplicationContext applicationContext = SpringContextHolder.getApplicationContext();
        GoodsMapper goodsMapper = applicationContext.getBean(GoodsMapper.class);
        // 获取仓库入库的数据
        String storeContent = (String) execution.getVariable("storeContent");
        if (StrUtil.isNotEmpty(storeContent)) {
            String[] ids = storeContent.split(",");
            for (String id : ids) {
                String temp[] = id.split("#");
                goodsMapper.updateStock(Integer.valueOf(temp[0]), Integer.valueOf(temp[1]));
            }
        }
    }

}
